//
//  Status.m
//  OCMicroBlog
//
//  Created by 002 on 15/11/6.
//  Copyright © 2015年 002. All rights reserved.
//

#import "Status.h"

@implementation Status

+ (instancetype)initWithDict:(NSDictionary *)dict {
    
    Status *status = [[Status alloc] init];
    
    [status setValuesForKeysWithDictionary:dict];
    
    return status;
}

// 针对 ‘对象’ 做的处理
- (void)setValue:(id)value forKey:(NSString *)key {
    
    // 1. 判断是否是 |uesr|
    if ([key isEqualToString:@"user"]) {
        
        NSDictionary *dict = value;
        if (dict) {
            self.user = [User userWithDict:dict];
        }

        return;
    }
    
    // 2. 判断是否是 |retweeted_status|
    if ([key isEqualToString:@"retweeted_status"]) {
        
        NSDictionary *dict = value;
        if (dict) {
            self.retweeted_status = [Status initWithDict:dict];
        }
        
        return;
    }

    [super setValue:value forKey:key];
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {}

/**
 *  模型调试信息
 *
 *  @return
 */
- (NSString *)description {
    
    NSArray *keys = @[@"created_at",
                      @"id",
                      
                      @"source",
                      @"user",
                      @"pic_urls",
                      @"retweeted_status"];
    
    return [self dictionaryWithValuesForKeys:keys].description;
}

@end
